package com.gosophia.util;

import com.gosophia.commons.Page;
import com.gosophia.commons.web.bean.RequestResult;

public class RequestResultUtil {

	private static RequestResult requestResult;
	private static final String CODE_1 = "1";
	private static final String CODE_0 = "0";
	private static final String REGULAR = "正常";
	private static final String NOTDATA = "没数据";

	/**
	 * 获取page对象的请求结果
	 * 
	 * @param page
	 * @return
	 */
	public static RequestResult getPageRequestResult(Page page) {
		requestResult=new RequestResult();
		String rsltCode = page.getResult().size() == 0 ? CODE_1 : CODE_0;
		String message = rsltCode.equals(CODE_0) ? REGULAR : NOTDATA;
		getRequestResult().setRsltCode(rsltCode);
		getRequestResult().setMessage(message);
		return requestResult;
	}

	/**
	 * 获取普通对象的请求结果
	 * 
	 * @param obj
	 * @return
	 */
	public static RequestResult getObjectRequestResult(Object obj) {
		requestResult=new RequestResult();
		String rsltCode = obj == null ? CODE_1 : CODE_0;
		String message = rsltCode == CODE_0 ? REGULAR : NOTDATA;
		getRequestResult().setRsltCode(rsltCode);
		getRequestResult().setMessage(message);
		return requestResult;
	}

	/**
	 * 没有返回结果
	 * 
	 * @return
	 */
	public static RequestResult getRequestResult() {
		requestResult=new RequestResult();
		getRequestResult().setRsltCode(CODE_0);
		getRequestResult().setMessage(REGULAR);
		return requestResult;
	}
	/**
	 * 没有返回结果
	 * 
	 * @return
	 */
	public static RequestResult getRequestResult(String message) {
		requestResult=new RequestResult();
		getRequestResult().setRsltCode(CODE_0);
		getRequestResult().setMessage(message);
		return requestResult;
	}
}
